#include <bits/stdc++.h>
using namespace std;
class Tnode{
public:
    int data;
    Tnode* pLchild;
    Tnode* pRchild;
    Tnode(int d,Tnode* l = nullptr,Tnode* r = nullptr)
    {
        data = d;
        pLchild = l;
        pRchild = r;
    }
};
//方便调试，前序遍历
void travel(Tnode* root)
{
    if(!root)
        return;
    else{
        cout<<root->data<<" ";
        travel(root->pLchild);
        travel(root->pRchild);
    }
}
void MirrorTree(Tnode* pRoot)
{
    if(!pRoot)
        return;
    if(!pRoot->pRchild||!pRoot->pLchild)
        return;
    //交换根节点左右子树
    Tnode* t = pRoot->pLchild;
    pRoot->pLchild = pRoot->pRchild;
    pRoot->pRchild = t;
    //左子数递归调用方法
    if(pRoot->pLchild)
        MirrorTree(pRoot->pLchild);
    //右子数递归调用方法
    if(pRoot->pRchild)
        MirrorTree(pRoot->pRchild);


}

int main() {
    Tnode* a = new Tnode(3);
    Tnode* b = new Tnode(4);
    Tnode* c = new Tnode(5);
    Tnode* d = new Tnode(6);
    Tnode* e = new Tnode(7);
    a->pLchild = b;
    a->pRchild = c;
    b->pLchild = d;
    b->pRchild = e;
//    travel(a);
//    Tnode* re = a;
    MirrorTree(a);
    travel(a);
//    cout<<a->pLchild->data<<a->pRchild->data<<endl;

    delete a,b,c,d,e;
    return 0;
}